const regs = {
    email: /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/,
    number: /^\+?[1-9][0-9]*$/,
    password: /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z~!@#$%^&*_]{8,}$/,
    version: /^[0-9\.]+$/
}
const verify = (rule: { message: string | undefined }, value: any, reg: RegExp, callback: any) => {
    if (value) {
        if (reg.test(value)) {
            callback()
        } else {
            callback(new Error(rule.message))
        }
    } else {
        callback()
    }
}

const checkPassword = (value: string) => {
    return regs.password.test(value);
}

const checkEmail = (value: string) => {
    return regs.email.test(value);
}

const password = (rule: any, value: any, callback: any) => {
    return verify(rule, value, regs.password, callback)
}

const number = (rule: any, value: any, callback: any) => {
    return verify(rule, value, regs.number, callback)
}
export default {
    checkPassword,
    checkEmail,
    password,
    number
} as any;
